package com.example.zhucongjdbc.controller;

import com.example.zhucongjdbc.entity.User;
import com.example.zhucongjdbc.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Author:mayc
 * @Date:2020/3/9 21:20
 */
@RestController
@RequestMapping("v1")
@Slf4j
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("/users")
    public Object list() {
        return userService.list();
    }

    @GetMapping("/add")
    public Object add(@RequestParam Integer id, @RequestParam String username, @RequestParam String  password) {
        User user = new User();
        user.setId(id);
        user.setUsername(username);
        user.setPassword(password);
        return userService.addUser(user);
    }

    @GetMapping("/adds")
    public Object addList() {
        for(int i=100;i<150;i++) {
            User user = new User();
            user.setId(i);
            user.setUsername("forezp"+(i));
            user.setPassword("1233edwd");
            long resutl = userService.addUser(user);
            log.info("insert:"+user.toString()+" result:"+resutl);
        }
        return "ok";
    }


}
